package oop封装;

import java.io.*;
import java.net.DatagramPacket;
import java.net.Socket;
import java.util.Scanner;

/**
 * 在线聊天室：客户端
 * 目标：实现oop封装结构，多用户收发消息
 * 客户端实现：读写分离
 */
public class Client {
    public static void main(String[] args) {
        //1.指定服务器端的IP和端口号
        System.out.println("------------Client------------");
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            System.out.print("请输入您的名字：");
            String name = br.readLine();
            System.out.println(name + "欢迎来到聊天室");
            Socket socket = new Socket("localhost",8888);
            new Thread(new Send(socket,name)).start();
            new Thread(new Reves(socket)).start();
        } catch (IOException e) {
            e.printStackTrace();
        }
        //发送线程

    }
    /*static class Resver{
       private Socket socket;
       private DataInputStream dis;

       public Resver(){
           try {
               socket = new Socket("localhost",8888);
               dis = new DataInputStream(socket.getInputStream());
               dos = new DataOutputStream(socket.getOutputStream());
           } catch (IOException e) {
               closeAll(socket,dis,dos);
           }
       }
       //发送信息
        public void resver(){
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            try {
                mag = br.readLine();
                if (mag != null){
                    dos.writeUTF(mag);
                    dos.flush();
                }else {
                    closeAll(socket, dos, dis);
                }
            } catch (IOException e) {
                closeAll(socket,dos,dis);
            }

        }
        //接收信息
        public void send(){
            try {
                mag = dis.readUTF();
                System.out.println(mag);
            } catch (IOException e) {
                closeAll(socket,dis,dos);
            }
        }
        //释放资源
        public void closeAll(Closeable... closeables){
           for (Closeable close:closeables){
               try {
                   close.close();
                   isRunneing = false;
               } catch (IOException e) {
                   e.printStackTrace();
               }
           }
        }*/

}
